package com.ruoyi.project.dict.materialTopicAsso.controller;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.dict.materialTopicAsso.domain.MaterialTopicAsso;
import com.ruoyi.project.dict.materialTopicAsso.service.IMaterialTopicAssoService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 专题资料Controller
 *
 * @author shixiangwen
 * @date 2022-02-24
 */
@Controller
@RequestMapping("/dict/materialTopicAsso")
public class MaterialTopicAssoController extends BaseController {
    private String prefix = "dict/materialTopicAsso";

    @Autowired
    private IMaterialTopicAssoService materialTopicAssoService;

    @RequiresPermissions("dict:materialTopicAsso:view")
    @GetMapping("/{topicId}")
    public String materialTopicAsso(@PathVariable("topicId") Integer topicId, ModelMap mmap) {
        mmap.put("topicId", topicId);
        return prefix + "/materialTopicAsso";
    }

    /**
     * 查询专题资料列表
     */
    @RequiresPermissions("dict:materialTopicAsso:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(MaterialTopicAsso materialTopicAsso) {
        startPage();
        List<MaterialTopicAsso> list = materialTopicAssoService.selectMaterialTopicAssoList(materialTopicAsso);
        return getDataTable(list);
    }

    /**
     * 导出专题资料列表
     */
    @RequiresPermissions("dict:materialTopicAsso:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(MaterialTopicAsso materialTopicAsso) {
        List<MaterialTopicAsso> list = materialTopicAssoService.selectMaterialTopicAssoList(materialTopicAsso);
        ExcelUtil<MaterialTopicAsso> util = new ExcelUtil<MaterialTopicAsso>(MaterialTopicAsso.class);
        return util.exportExcel(list, "materialTopicAsso");
    }

    /**
     * 新增专题资料
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存专题资料
     */
    @RequiresPermissions("dict:materialTopicAsso:add")
    @Log(title = "专题资料", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(MaterialTopicAsso materialTopicAsso) {
        return toAjax(materialTopicAssoService.insertMaterialTopicAsso(materialTopicAsso));
    }

    /**
     * 修改专题资料
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        MaterialTopicAsso materialTopicAsso = materialTopicAssoService.selectMaterialTopicAssoById(id);
        mmap.put("materialTopicAsso", materialTopicAsso);
        return prefix + "/edit";
    }

    /**
     * 修改保存专题资料
     */
    @RequiresPermissions("dict:materialTopicAsso:edit")
    @Log(title = "专题资料", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(MaterialTopicAsso materialTopicAsso) {
        return toAjax(materialTopicAssoService.updateMaterialTopicAsso(materialTopicAsso));
    }

    /**
     * 删除专题资料
     */
    @RequiresPermissions("dict:materialTopicAsso:remove")
    @Log(title = "专题资料", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(materialTopicAssoService.deleteMaterialTopicAssoByIds(ids));
    }
}
